import myAxios from './myAxios';
import jsonp from 'jsonp';
import qs from 'querystring';
import { BASE_URL,WEATHER_KEY } from '../config'
const { stringify } = qs;

// 获取天气信息（高德地图API），jsonp解决跨域问题
export const reqWeather = (city) =>{
    const weatherObj ={
        output:'JSON',
        extensions:'base',
        city:city,
        key:WEATHER_KEY
    }
   return new Promise((resolve,reject)=>{
        jsonp(`https://restapi.amap.com/v3/weather/weatherInfo?${stringify(weatherObj)}`,(err,data)=>{
            if(err){
                // console.log(err);
                return new Promise(()=>{})
            }else if(data.status === "0"){
                return new Promise(()=>{})
            }else{
                resolve(data.lives[0])
            }
        })
   })
}
// 获取当前位置
export const reqCity =()=>{
    return new Promise((resolve,reject)=>{
        jsonp(`http://restapi.amap.com/v3/ip?key=${WEATHER_KEY}`,(err,data)=>{
            if(err){
                // console.log(err);
                return new Promise(()=>{})
            }else if(data.status === "0"){
                return new Promise(()=>{})
            }else{
                resolve(data)
            }
        })
   })
}
// 发起登录请求
export const reqLogin = (userNum,password) => myAxios.post(`${BASE_URL}/api/training/login`,stringify({userNum,password}))

// 发起讲师登录请求
export const reqTeacherLogin = (userNum,password) => myAxios.post(`${BASE_URL}/api/training/teacher/login`,stringify({userNum,password}))

// 请求删除图片（根据图片唯一名删除）
export const reqDeletePicture = (name)=> myAxios.get(`${BASE_URL}/manage/img/delete`,{name})

// 请求获取所有用户信息
export const reqUserList = () => myAxios.get(`${BASE_URL}/api/training/user/student/list`)

// 请求添加用户
export const reqAddUser =  (userObj)=> myAxios.post(`${BASE_URL}/api/training/user/student/add`,stringify(userObj))

// 请求更新用户
export const reqUpdateUser =  (userObj)=> myAxios.post(`${BASE_URL}/api/training/user/student/update`,stringify(userObj))

// 请求删除用户
export const reqDeleteUser =  (id)=> myAxios.post(`${BASE_URL}/api/training/user/student/delete`,stringify({id}))

// 根据关键字搜索用户
export const reqSearchUser = (searchType,keyWord)=> myAxios.get(`${BASE_URL}/api/training/user/search`,{params:{[searchType]:keyWord}})

// 获取所有商品列表请求
export const reqAttributeListAll = () => {return myAxios.get(`${BASE_URL}/api/training/course/attribute/listAll`)}

// 获取商品列表状态为使用请求
export const reqAttributeList = () => {return myAxios.get(`${BASE_URL}/api/training/course/attribute/list`)}

// 修改分类管理请求
export const reqUpdateAttribute = (attributeObj) => myAxios.post(`${BASE_URL}/api/training/course/attribute/update`,stringify(attributeObj))

// 修改分类管理状态
export const reqUpdateAttributeStatus = (attributeObj) => myAxios.post(`${BASE_URL}/api/training/course/attribute/updateStatus`,stringify(attributeObj))

// 新增分类管理请求
export const reqAddAttribute  = (attributeName) => myAxios.post(`${BASE_URL}/api/training/course/attribute/add`,stringify({attributeName}))

// 请求获取所有讲师信息
export const reqTeacherList = () => myAxios.get(`${BASE_URL}/api/training/user/teacher/list`)

// 请求添加讲师信息
export const reqAddTeacher =  (teacherObj)=> myAxios.post(`${BASE_URL}/api/training/user/teacher/add`,stringify({...teacherObj}))

// 请求更新讲师信息
export const reqUpdateTeacher = (teacherObj)=> myAxios.post(`${BASE_URL}/api/training/user/teacher/update`,stringify({...teacherObj}))

// 根据关键字搜索讲师
export const reqSearchTeacher = (searchType,keyWord)=> myAxios.get(`${BASE_URL}/api/training/teacher/search`,{params:{[searchType]:keyWord}})

// 根据讲师Id获取讲师信息
export const reqSearchTeacherById = (id)=> myAxios.get(`${BASE_URL}/api/training/teacher/searchById`,{params:{id}})

// 请求删除讲师信息
export const reqDeleteTeacher =  (id)=> myAxios.post(`${BASE_URL}/api/training/user/teacher/delete`,stringify({id}))

// 请求获取所有课程信息
export const reqContentList = () => myAxios.get(`${BASE_URL}/api/training/course/content/list`)

// 请求添加课程信息
export const reqAddContent = (contentObj) =>{ return myAxios.post(`${BASE_URL}/api/training/course/content/add`,stringify(contentObj))}

// 请求修改课程信息
export const reqUpdateContent = (contentObj) =>{ return myAxios.post(`${BASE_URL}/api/training/course/content/update`,stringify(contentObj))}

// 根据id请求课程信息
export const reqSearchContentById =(id) => myAxios.get(`${BASE_URL}/api/training/course/content/search`,{params:{'id':id}})

// 请求删除课程信息
export const reqDeleteContent = (id) => myAxios.post(`${BASE_URL}/api/training/course/content/delete`,stringify({id}))

// 根据关键字搜索课程信息
export const reqSearchContent = (searchType,keyWord)=> myAxios.get(`${BASE_URL}/api/training/course/content/search`,{params:{[searchType]:keyWord}})

// 修改课程信息状态
export const reqUpdateContentStatus=(id,courseStatus) => { return myAxios.post(`${BASE_URL}/api/training/course/content/updateStatus`,stringify({id,courseStatus}))}

// 获取公告信息
export const reqNoticeList=() => myAxios.get(`${BASE_URL}/api/training/push/notice/list/all`)

// 修改公告使用状态
export const reqUpdateNoticeUseStatus =(id,useStatus) => { return myAxios.post(`${BASE_URL}/api/training/push/notice/updateUseStatus`,stringify({id,useStatus}))}

// 删除公告 
export const reqDeleteNotice = (id)=> myAxios.post(`${BASE_URL}/api/training/push/notice/delete`,stringify({id}))

// 修改公告
export const reqUpdateNotice = (noticeObj) =>{ return myAxios.post(`${BASE_URL}/api/training/push/notice/update`,stringify(noticeObj))}

// 添加公告
export const reqAddNotice = (noticeObj) =>{ return myAxios.post(`${BASE_URL}/api/training/push/notice/add`,stringify(noticeObj))}

// 获取文章信息
export const reqArticleList=() => myAxios.get(`${BASE_URL}/api/training/push/article/list/all`)

// 删除文章
export const reqDeleteArticle = (id)=> myAxios.post(`${BASE_URL}/api/training/push/article/delete`,stringify({id}))

// 修改文章使用状态
export const reqUpdateArticleUseStatus =(id,useStatus) => { return myAxios.post(`${BASE_URL}/api/training/push/article/updateUseStatus`,stringify({id,useStatus}))}

// 添加文章
export const reqAddArticle = (articleObj) =>{ return myAxios.post(`${BASE_URL}/api/training/push/article/add`,stringify(articleObj))}

// 修改文章
export const reqUpdateArticle = (articleObj) =>{ return myAxios.post(`${BASE_URL}/api/training/push/article/update`,stringify(articleObj))}

// 根据选课学生Id获取学生选课信息
export const reqSearchStudentInfo = (userId)=> myAxios.get(`${BASE_URL}/api/training/information/search`,{params:{userId}})

// 根据课程Id获取学生选课信息
export const reqSearchByCourseId = (courseId)=> myAxios.get(`${BASE_URL}/api/training/information/search`,{params:{courseId}})

// 获取讲师选课信息
export const reqSearchTeacherInfo  = (searchType,keyWord)=> myAxios.get(`${BASE_URL}/api/training/course/content/search`,{params:{[searchType]:keyWord}})

// 获取所有选课信息
export const reqRelationList = ()=> myAxios.get(`${BASE_URL}/api/training/information/list`)

// 添加课程信息
export const reqAddRelation = (relationObj) =>  myAxios.post(`${BASE_URL}/api/training/information/add`,stringify(relationObj))

// 同意退课
export const reqUpdateRelationStatus = (id) => myAxios.post(`${BASE_URL}/api/training/information/updateStatus`,stringify({id}))

// 拒绝退课
export const reqUpdateRejectStatus = (id) => myAxios.post(`${BASE_URL}/api/training/information/updateReject`,stringify({id}))

// 根据不同状态获取学生选课信息
export const reqSearchRelation = (status)=> myAxios.get(`${BASE_URL}/api/training/information/search`,{params:{status}})

// 获取被拒绝退课的学生选课信息
export const reqSearchReject = (reject)=> myAxios.get(`${BASE_URL}/api/training/information/search`,{params:{reject}})

// 讲师获取所有上架课程信息
export const reqCurriculumList = () => myAxios.get(`${BASE_URL}/api/training/curriculum/list`)

// 根据关键字搜索上架课程信息
export const reqSearchCurriculum = (searchType,keyWord)=> myAxios.get(`${BASE_URL}/api/training/curriculum/search`,{params:{[searchType]:keyWord}})

// 获取所有当前讲师的上架课程
export const reqTeacherSubjectList =  () => myAxios.get(`${BASE_URL}/api/training/teacher/personal/course`)

// 获取讲师课程的学员
export const reqSearchSubjectStudent =(courseId)=> myAxios.get(`${BASE_URL}/api/training/teacher/information/searchByCourseId`,{params:{courseId}})

// 提交学员分数
export const reqUpdateStudentScore = (id,mark) => myAxios.post(`${BASE_URL}/api/training/teacher/information/updateMark`,stringify({id,mark}))

// 讲师获取信息
export const reqTeacherInfo = ()=> myAxios.get(`${BASE_URL}/api/training/teacher/info`)

// 请求更新讲师个人信息
export const reqUpdateTeacherInfo = (teacherObj)=> myAxios.post(`${BASE_URL}/api/training/teacher/info/update`,stringify({...teacherObj}))

// 讲师修改密码
export const reqUpdateTeacherPassword = (oldPassword,newPassword)=> myAxios.post(`${BASE_URL}/api/training/teacher/password/update`,stringify({oldPassword,newPassword}))

// 讲师修改密码
export const reqUpdateAdminPassword = (oldPassword,newPassword)=> myAxios.post(`${BASE_URL}/api/training/admin/password/update`,stringify({oldPassword,newPassword}))

// 获取已启用公告信息
export const reqAllNoticeList=() => myAxios.get(`${BASE_URL}/api/training/push/notice/list`)

// 获取反馈意见信息
export const reqFeedbackList=() => myAxios.get(`${BASE_URL}/api/training/admin/feedback/list`)
